package com.blog.common;

import com.blog.vo.PageVO;
import com.github.pagehelper.PageHelper;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


/**
 * @author tangqj
 * @Description 切面
 * @create 2020/2/18 14:59
 */
@Aspect
@Component
public class PageHelperAspect {
    @Pointcut("@annotation(com.blog.common.PageHelperLog)")
    private void pointcut(){

    }

    //mybatis分页点
    @Around("pointcut()&&@annotation(pageHelperLog)")
    public Object access(ProceedingJoinPoint point, PageHelperLog pageHelperLog) throws Throwable {
       Object[] as = point.getArgs();
       PageVO pageVO = new PageVO();
       for (int i=0;i<as.length;i++){
           pageVO = (PageVO) as[0];
       }
       PageHelper.startPage(pageVO.getPage(), pageVO.getLimit());
       // 消息
       String desc = pageHelperLog.desc();
       return point.proceed();
    }
}
